#include "stdafx.h"
#include "ASN1UTCTime.h"

typedef std::pair<std::string, std::vector<byte>> utctimeEncodingParam;

class ASN1UTCTimeEncodingTestCase : public ::testing::TestWithParam<utctimeEncodingParam>
{
};

TEST_P(ASN1UTCTimeEncodingTestCase, Encode)
{
	AppliedCryptography::ASN1UTCTime val(GetParam().first);
	std::vector<byte> ret;

	ASSERT_NO_THROW(ret = val.encode());

	// Output size should be as expected
	ASSERT_EQ(GetParam().second.size(), ret.size()) << "Value: " << GetParam().first;

	for(unsigned int i = 0; i < GetParam().second.size(); ++i)
	{
		EXPECT_NO_THROW(EXPECT_EQ((int)GetParam().second.at(i), (int)ret.at(i)) 
			<< "Index i: " << i << "\n"
			<< "Value: " << GetParam().first);
	};
};

std::string str3("2004-12-20 15:56:03");
byte bytesStr3[] = {0x17, 0x0d, 0x30, 0x34, 0x31, 0x32, 0x32, 0x30, 0x31, 0x35, 0x35, 0x36, 0x30, 0x33, 0x5a};
std::vector<byte> vectStr3(bytesStr3, bytesStr3 + sizeof(bytesStr3) / sizeof(byte));

INSTANTIATE_TEST_CASE_P(ASN1UTCTimeEncodingTest,
                        ASN1UTCTimeEncodingTestCase,
						::testing::Values( 
							utctimeEncodingParam(str3, vectStr3) )
						);


TEST(ASN1UTCTimeTestCase, Set)
{
	AppliedCryptography::ASN1UTCTime val("2004-12-20 15:56:03");

	EXPECT_EQ(2004, val.get().tm_year+1900);
	EXPECT_EQ(12, val.get().tm_mon+1);
	EXPECT_EQ(20, val.get().tm_mday);

	EXPECT_EQ(15, val.get().tm_hour);
	EXPECT_EQ(56, val.get().tm_min);
	EXPECT_EQ(3, val.get().tm_sec);
};
